<?php
include('/var/www/html/new/d/module/api/function.class.php');
if (!class_exists("go_sql")){
	include("/var/www/html/new/conf/le.je");
	$le=new go_sql();
	$le->connect();
}
if(!isset($_REQUEST['Action']) || $_REQUEST['Action']!= "MOD"){
	exit("200|0|0|0");
}
if($_REQUEST['Action'] == "MOD"){//修改 and 修改

	logfile(json_encode($_REQUEST),'api_cancel');

	$PFT_infunction = new AllFunction();
	$Ordern = $_REQUEST['Ordern'];
	$Ordern_xml = $PFT_infunction->Select_PFTorder($Ordern); 
	$UUlid = (int)$Ordern_xml->Rec->UUlid; //景区id
	$UUtprice=(string)$Ordern_xml->Rec->UUtprice; //结算价

	switch($UUlid){ 
		case 5322: //鼓浪屿（九天）
			if($_REQUEST['Tnum'] == 0){
				$result = file_get_contents("http://max.12301.cc/gate_machine_order_cancel.php?ordern=".$Ordern);
			}else{
				$result = file_get_contents("http://max.12301.cc/gate_machine_order_cancel.php?ordern=".$Ordern."&tnum=".$_REQUEST['Tnum']."&pirce=".$UUtprice);
			}
			if($result == 101) exit("1077|0|0|0");
			else { 
				$str = "update uu_order_fx_details set memo='gly_modify_success' where orderid=".$Ordern." limit 1";
				$GLOBALS['le']->query($str);
				exit("200|0|0|0");
			}
		break;

		case 8048:
		case 8055:
		case 8054:
			if($_REQUEST['Tnum'] == 0){//取消订单
				include_once('RuiJin/ruijin.class.php');
				$RJ = new RunJin($UUlid);  //九天-瑞金		
				$result = $RJ->removeOrder($Ordern);
				if($result == 101) exit("1077|0|0|0");
				else{
					$str = "update uu_order_fx_details set memo='100_3' where orderid=".$Ordern." limit 1";
					$GLOBALS['le']->query($str);
					exit("200|0|0|0");
				}
			}
		break;
	
		default:
			exit("1077|0|0|0");
		break;
	}
}
function logfile($word,$path){
	$filepath= '/var/www/html/new/d/logs/api/api_cancel/'.$path.'.txt';
	$word = date("Y-m-d H:i:s")."|".$word;
	if(file_exists($filepath)){
		$maxsize  = 1024*1024*10;
		$filesize = filesize($filepath);
		$filetype = end(explode(".",$filepath));
		$filename = substr($filepath,0,strpos($filepath,'.'));
		if($filesize>$maxsize)
			rename($filepath, $filename.'_'.date('YmdHis').'.'.$filetype);
	}
	$fp = fopen($filepath,"a");
	flock($fp, LOCK_EX);
	fwrite($fp,$word."\n");
	flock($fp, LOCK_UN);
	fclose($fp);
}
?>
